package com.hulei.memcached.memcachedjavaclient;

import com.whalin.MemCached.MemCachedClient;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class MemcachedController {

	@Resource
	private MemCachedClient memCachedClient;

	@RequestMapping("/memcachedIndex")
	public String memcachedIndex() throws InterruptedException {
		// 放入缓存
		boolean flag = memCachedClient.set("a", 1);
		System.out.println(flag);
		// 取出缓存
		Object a = memCachedClient.get("a");
		System.out.println(a);
		// 3s后过期
		memCachedClient.set("b", "2", new Date(3000));
		Object b = memCachedClient.get("b");
		System.out.println(b);

		Thread.sleep(3000);
		b = memCachedClient.get("b");
                System.out.println(a);
		System.out.println(b);
		return "abcd";
	}
}
